import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

@Entity("character_religions")
@ManualTimestamp()
export class CharacterReligionEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "characterId", unique: true })
  characterId!: number;

  @Column("varchar", { length: 64, comment: "教派名称" })
  name!: string;

  @Column("varchar", { length: 128, nullable: true, comment: "教派描述" })
  description!: string;

  @Column("int", { default: 1, comment: "教派等级" })
  level!: number;

  @Column("datetime", {
    comment: "加入时间",
  })
  joinedAt!: Date;

  @Column("datetime", {
    name: "updated_at",
    nullable: true,
    comment: "更新时间",
  })
  updated_at!: Date;

  // 关联关系
  @OneToOne(() => CharacterEntity, (character) => character.religion)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
